﻿@{
    ViewBag.Title = "知识类别权限管理";
    Layout = "~/Views/Shared/_ManagerLayoutPage.cshtml";
}

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-body" style="padding: 1.75rem 2.8125rem;">
                <div class="row ">
                    <div class="col-md-12 clearfix" style="padding-left:0px;">
                        <p style="font-size:15px;font-weight:bold;">知识类别权限管理</p>
                        <div class="my-4 row">
                            <div class="ml-3">
                                <a href="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/KnowledgeAuthManager/EditKnowledgeAuth" class="btn btn-primary">
                                    <i class="fa fa-align-center"></i> &nbsp; 新建知识类别权限
                                </a>
                            </div>
                            <div class="col-sm-3">
                            </div>

                        </div>
                    </div>
                </div>


                <div class="row">
                    <div class="col-md-12" style="padding-left: 0;">
                        <div class="card" style="border-color:#f6f6f6;">
                            <div class="card-body" style="padding: 0;">
                                <div class="table-responsive">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>类别</th>
                                                <th>子类别</th>
                                                <th>创建时间</th>
                                                <th>描述</th>
                                                <th style="text-align:center;">操作</th>
                                            </tr>
                                        </thead>
                                        <tbody id="module_content"></tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="row">
                    <div class="col-md-12">
                        <div class="pageindex" id="page_index" style="display:none;">
                            <a id="pre_page" style="cursor:pointer;">上一页</a>
                            <span id="current_num"></span>&nbsp;/&nbsp;<span id="total_num"></span>
                            <a id="next_page" style="cursor:pointer;">下一页</a>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
@section ChildPageScript{
            <script>
                var dictionary;
        $.ajax({
            url: "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")" + "@Url.Action("GetKnowledgeDictionary", "KnowledgeAuthManager")",
            type: "GET",
            async: false,
            dataType: "json",
            success: function(data){
                dictionary = data.Result.LtDictionaryItemTreeOutputInfos;
            }
        })

            var current_num;

            var total_num;

            $("#loading").hide();

            $(function () {

                ShowModuleContent(null,1);

            });
             $("#pre_page").click(function () {
                if (total_num != null) {
                    var i = parseInt(current_num);
                    if (i == 1) {

                    }
                    else if (i > 1) {

                        ShowModuleContent($("#pre_page"),i-1);
                    }


                }
            });
            $("#next_page").click(function () {
                if (total_num != null) {
                    var j = parseInt(total_num);
                    var i = parseInt(current_num);
                    if (j == i) {

                    }
                    else if (j > i) {

                        ShowModuleContent($("#next_page"),i+1);
                    }
                }

            });

            function SetPageNum() {
                $("#total_num").html(total_num);
                $("#current_num").html(current_num);
                if (total_num > 1) {
                    $("#page_index").show();
                }
            }
            function ShowModuleContent(obj,pagenum) {
                if (obj != null)
                {
                    $(obj).attr("disabled", "disabled");
                }
                $("#module_content").empty();
                $("#page_index").hide();
                $("#loading").show();

                $.ajax({

                url: "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")" + "@Url.Action("GetKnowledgeAuth", "KnowledgeAuthManager")",
                    dataType: "json",
                    data: { "pagenum": pagenum, "pagesize": 10, "para": $("#para").val()},
                    type: "get",
                    success: function (data) {
                        console.log(data);

                        if (data.IsError) {
                            Notic('error',data.Message);
                        }
                        else {
                            var html = "";
                            $(data.Result.content).each(function ()
                            {
                                var documentCategoryName = "";
                                var documentChildCategoryName = "";
                                for(var i = 0; i < dictionary.length; i++){
                                    if(dictionary[i].Value == this["DocumentCategory"]){
                                        documentCategoryName = dictionary[i].Name;

                                        for (var j = 0; j < dictionary[i].Children.length; j++){
                                            if(dictionary[i].Children[j].Value == this["DocumentChildCategory"]){
                                                documentChildCategoryName = dictionary[i].Children[j].Name;

                                                break;
                                            }
                                        }

                                        break;
                                    }
                                }

                                html += "<tr>";
                                html += "<td>" + this["DocumentCategory"] + " " + documentCategoryName + "</td>";

                                html += "<td>" + this["DocumentChildCategory"] + " " + documentChildCategoryName + "</td>";

                                html += "<td>" + this["CreateTime"].replace("T", " ") + "</td>";

                                html += "<td>" + this["Description"] + "</td>";

                                html += "<td style='text-align:center;'>" + (this["IsSystem"] == 1 ? "<a class='btn btn-outline-primary btn-sm' href='../KnowledgeAuthManager/KnowledgeAuthDetail?id=" + this["Id"] + "' target='_blank'>查看</a>" : "<a class='btn btn-outline-primary btn-sm' href='../KnowledgeAuthManager/KnowledgeAuthDetail?id=" + this["Id"] + "' target='_blank'>查看</a> <a class='btn btn-outline-warning btn-sm' href='../KnowledgeAuthManager/EditKnowledgeAuth?id=" + this["Id"] +"'>编辑</a>") + "</td>";

                                html += "</tr>";


                            });
                            $("#module_content").html(html);

                            total_num = data.Result.total_num;

                            current_num = pagenum;
                            SetPageNum();
                        }


                    },
                    fail: function (data) {


                    },
                    complete: function (data) {


                        $("#loading").hide();

                        $(obj).removeAttr("disabled");

                    }
                });
            }

            </script>
    }